
import axios from 'axios'

const instance = axios.create({
    baseURL: 'http://test.gpsserver.cn/'
    /* baseURL: 'http://192.168.31.124/' */
    /* baseURL: 'http://zyd.asrobot.cn/' */
});

instance.interceptors.request.use(function (config) {
    return config;
}, function (error) {
    return Promise.reject(error);
});

// 添加响应拦截器
instance.interceptors.response.use(function (response) {
    let data = response.data[0];
    console.log(data);
    switch (data.par) {
        case "succeed": {
            console.log(data)

            return data;
        }
        case "err_input":
            break;
        case "err_nodata":
            break;
    }
}, function (error) {
    return Promise.reject(error);
});

export default function api({methods , url , param = ''}) {
    return new Promise(function(resolve , reject) {
        instance[methods](
            url,
            param,
        ).then(function(responce) {
            resolve(responce)
        }).catch(function(error) {
            reject(error)
        })
    })
}